
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#include "GRTMaterial.h"

#include "GRTSdlGLUtils.h"
#include "GRTMemoryLeak.h"
//constructor
GRTMaterial::GRTMaterial()
{
	_ambient[0] = _ambient[3] = 1;
	_ambient[1] = _ambient[2] = 0;

	_diffuse[0] = _diffuse[3] = 1;
	_diffuse[1] = _diffuse[2] = 0;

	_specular[0] = _specular[1] = _specular[2] = _specular[3] = 1;

	_shininess = 20;

	_hTexture = -1;
	_textureName = "";
}

//destructor
GRTMaterial::~GRTMaterial(){}

//ambient setter
void GRTMaterial::setAmbient(float r, float g, float b, float a)
{
	_ambient[0] = r;
	_ambient[1] = g;
	_ambient[2] = b;
	_ambient[3] = a;
}

//diffuse setter
void GRTMaterial::setDiffuse(float r, float g, float b, float a)
{
	_diffuse[0] = r;
	_diffuse[1] = g;
	_diffuse[2] = b;
	_diffuse[3] = a;
}

//specular setter
void GRTMaterial::setSpecular(float r, float g, float b, float a)
{
	_specular[0] = r;
	_specular[1] = g;
	_specular[2] = b;
	_specular[3] = a;
}

//shininess setter
void GRTMaterial::setShininess(float s)
{
	_shininess = s;
}

//ambient getter
float* GRTMaterial::getAmbient()
{
	return _ambient;
}

//diffuse getter
float* GRTMaterial::getDiffuse()
{
	return _diffuse;
}

//specular getter
float* GRTMaterial::getSpecular()
{
	return _specular;
}

//shininess getter
float GRTMaterial::getShininess()
{
	return _shininess;
}

//load a texture
void GRTMaterial::setTexture(const string& filename)
{
	_textureName = filename;
	_hTexture = loadTexture(filename.c_str(), false);
}

//set the name of the texture
void GRTMaterial::setTextureName(const string& filename)
{
	_textureName = filename;
}

//load the texture using _textureName
void GRTMaterial::setTexture()
{
	_hTexture = loadTexture(_textureName.c_str(), false);
}

//texture getter
int GRTMaterial::getTexture()
{
	return _hTexture;
}

//get the texture filename
string GRTMaterial::getTextureFilename()
{
	return _textureName;
}